package com.simon.mctm.biz.sys.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.toolkit.CollectionUtils;
import com.simon.mctm.base.PageResult;
import com.simon.mctm.biz.sys.bean.Dept;
import com.simon.mctm.biz.sys.dao.DeptMapper;
import com.simon.mctm.biz.sys.service.DeptService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.simon.mctm.exception.OperationFailedException;
import com.simon.mctm.utils.Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门 服务实现类
 * </p>
 *
 * @author simon
 * @since 2018-06-15
 */
@Service
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements DeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public PageResult calPage(String simplename, Integer pageSize) {
        try {
            List<Dept> deptList = deptMapper.selectList(
                    new EntityWrapper<Dept>().like("simplename", simplename)
            );
            if (CollectionUtils.isNotEmpty(deptList)) {
                return new PageResult(deptList.size(), Utils.calPages(deptList.size(), pageSize));
            } else {
                return new PageResult(0, 0);
            }
        } catch (Exception ex) {
            throw new OperationFailedException(ex.getMessage());
        }
    }

}
